<?php
/**
 * UploadFile
 * - Class process uploaded files
 * - Copyright&copy; Runsystem
 * @author Do Truong Giang
 * @since 1.0 - Jul 19, 2008
 * $Id: UploadFile.class.php,v 1.3 2009/08/12 02:51:00 quyennt Exp $
 */
class UploadFile {
	/**
	 * copy
	 * - Copy an upload file to a location
	 * @param String $fileName The name of &lt;input type='file'&gt;
	 * @param String $newName The absolute location of destination
	 * @return Boolean True if the file exists, otherwise false
	 */
	public static function copy($fileName, $newName) {
		$success = false;
		if (isset($_FILES[$fileName])) {
			$success = copy($_FILES[$fileName]["tmp_name"], $newName);
		}
		return $success;
	}
	/**
	 * move
	 * - Copy one file to another place, remove the source file
	 * @param String $src Source file, absolute path
	 * @param String $dest Destination file, absolute path
	 * @return Boolean True if move successfully, otherwise return false
	 */
	public static function move($src, $dest) {
		$success = false;
		if (is_file($src)) {
			$success = copy($src, $dest);
			unlink($src);
		}
		return $success;
	}
	/**
	 * listFolder
	 * - List all files, directory in a folder
	 * @author Do Truong Giang
	 * 
	 * @param String $folder The absolute path to folder
	 * @return Array The list of file name inside folder
	 */
	public static function listFolder($folder) {
		$list = array();
		$dir = dir($folder);
		while($filename = $dir->read()) {
			$list[] = $filename;
		}
		$dir->close();
		return $list;
	}
	/**
	 * remove
	 * - Remove file
	 * @param $tring $src
	 * @author Nguyen Thanh Quyen
	 * @since 1.0 - Jul 26, 2009
	 */
	public static function remove($src) {
		if (is_file($src)) {
			unlink($src);
			return true;
		}
		else {
			return false;
		}
	}
}
?>